package com.leo.zerocopy;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @author du
 */
public class Client {
    public static void main(String[] args) throws IOException {

        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 7000));

        FileChannel fileChannel = new FileInputStream("xxx.zip").getChannel();

        // 将文件channel，拷贝到socketChannel，底层使用sendfile
        // linux可以一次性传输完，但windows每次只能传输8M，所以需要自行在代码中处理
        fileChannel.transferTo(0, fileChannel.size(), socketChannel);

        fileChannel.close();
        socketChannel.close();
    }
}
